package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.client.Bank;
import com.acme.bankapp.domain.bank.client.Client;
import com.acme.bankapp.domain.bank.client.ClientRegistrationListener;
import com.acme.bankapp.domain.bank.client.Gender;
import com.acme.bankapp.exception.bank.BankException;
import com.acme.bankapp.service.bank.network.BankServer;

import java.io.IOException;

public class BankApplication {

    public static ClientRegistrationListener listeners[] = new ClientRegistrationListener[2];

    public static Bank bank = new Bank(listeners);

    public static EmailService emailService = new EmailService();


    public static void main(String[] args) throws BankException, IOException {

        String
                path = "";

        if (args.length >= 2) {
            switch (args[0]) {
                case "-loadbank":
                    path = args[1];
                    listeners[0] = new Bank.PrintClientListener();
                    listeners[1] = new Bank.EmailNotificationListener();
                    try {
                        BankService.readBank(bank, path);


                        BankService.addClient(bank, new Client("Petrov Kolya", Gender.Male, 3.56, 32.3, 46.52));
                        BankService.addClient(bank, new Client("111", Gender.Male, 3.56));
                        BankService.addClient(bank, new Client("222", Gender.Male, 3.56, 32.3, 46.52));
                        BankService.addClient(bank, new Client("3333", Gender.Male, 3.56, 32.3));
                        BankService.addClient(bank, new Client("444", Gender.Male, 3.56, 32.3, 46.52));
                        BankService.addClient(bank, new Client("5555", Gender.Male, 3.56, 32.3, 46.52));
                        emailService.close();
                         BankService.saveBank(bank, "a:\\1.txt");
                    } catch (Exception e) {
                        System.out.printf("Exception: %s\n", e.getStackTrace());
                    }

                    if (args.length == 3) {
                        switch (args[2]) {
                            case "-server":
                                BankServer server = new BankServer();
                                server.startServer();
                                break;
                        }
                    }
                    break;
                default:
                    System.out.printf("Invalid arguments\n");
            }
        }


    }

}